package com.zjsru.studyplan1;

import java.util.ArrayDeque;
import java.util.Deque;

/***
 *
 * 只出现一次的数字
 * (线性时间复杂度和常数空间复杂度)
 * 输入: [4,1,2,1,2]
 * 输出: 4
 *
 */

public class singleNumber {
    public int singleNumber(int[] nums) {
        int single = 0;
        for (int num: nums) {
            single ^= num;
        }
        return single;
    }
    public static void main(String[] args){
        singleNumber singleNumber = new singleNumber();
        int[] nums = new int[]{4,1,2,1,2};
        System.out.println(singleNumber.singleNumber(nums));
    }
}
